package com.hhxy.rabbitmq.demo07;

import com.hhxy.rabbitmq.utils.RabbitMqUtil;
import com.rabbitmq.client.Channel;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author ghp
 * @date 2023/2/25
 * @title
 * @description
 */
public class TopicLogs {

    // 交换机名
    public static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtil.getChannel();
        Scanner sc = new Scanner(System.in);
        // 路由key，用于给交换机匹配队列
        Map<String, String> routingKeys = new HashMap<>();
        routingKeys.put("orange", "AA");
        routingKeys.put("orange.", "BB");
        routingKeys.put(".orange.", "CC"); // 匹配成功: Q1  *.orange.*
        routingKeys.put("others.orange.others", "DD"); // 匹配成功 Q1  *.orange.*
        routingKeys.put("others.orange.rabbit", "EE"); // 匹配成功 Q1 Q2 *.orange.*  *.*.rabbit
        routingKeys.put("others..rabbit", "FF"); // 匹配成功 Q2 *.*.rabbit
        routingKeys.put("..rabbit", "GG"); // 匹配成功 Q2 *.*.rabbit
        routingKeys.put("lazy", "HH"); // 匹配成功 Q2 lazy.#
        routingKeys.put("lazy.others", "II"); // 匹配成功 Q2 lazy.#
        routingKeys.put("lazy.others.", "JJ"); // 匹配成功 Q2 lazy.#
        routingKeys.put("lazy....", "KK"); // 匹配成功 Q2 lazy.#
        routingKeys.put("lazy.orange.rabbit", "LL"); // 匹配成功 Q2  lazy.#  *.*.rabbit
        routingKeys.put("quick.orange.orange.rabbit", "MM"); // 匹配成功 Q1 Q2  *.orange.*  lazy.#

        // 发送消息
        while (sc.hasNext()) {
            String routingKey = sc.next();
            String message = sc.next();
            channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes("UTF-8"));
            System.out.println("生产者发送消息: " + message);
        }
    }
}
